import 'dart:async';

import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_heating/ui/src/theme.dart';
import 'package:get/get.dart';

class UiRefresher extends StatelessWidget {
  const UiRefresher({
    super.key,
    this.controller,
    this.scrollController,
    this.footer,
    this.header,
    this.child,
    this.onRefresh,
    this.onLoad,
  });
  final EasyRefreshController? controller;
  final ScrollController? scrollController;
  final Header? header;
  final Footer? footer;
  final Widget? child;
  final FutureOr<dynamic> Function()? onRefresh;
  final FutureOr<dynamic> Function()? onLoad;
  @override
  Widget build(BuildContext context) {
    return EasyRefresh(
      controller: controller,
      scrollController: scrollController,
      onRefresh: onRefresh,
      onLoad: onLoad,
      header: header ??
          ClassicHeader(
            dragText: 'Pull to load'.tr,
            armedText: 'Release ready'.tr,
            readyText: 'Refreshing...'.tr,
            processingText: 'Refreshing...'.tr,
            processedText: 'Succeeded'.tr,
            noMoreText: 'No more'.tr,
            failedText: 'Failed'.tr,
            messageText: 'Last updated at %T'.tr,
          ),
      footer: footer ??
          ClassicFooter(
            showMessage: false,
            textStyle: TextStyle(color: UiTheme(context).normalColor),
            messageStyle: TextStyle(color: UiTheme(context).normalColor),
            iconTheme: IconThemeData(color: UiTheme(context).normalColor),
            dragText: 'Pull to load'.tr,
            armedText: 'Release ready'.tr,
            readyText: 'Loading...'.tr,
            processingText: 'Loading...'.tr,
            processedText: 'Load Succeeded'.tr,
            noMoreText: 'No more'.tr,
            failedText: 'Failed'.tr,
            messageText: 'Last updated at %T'.tr,
          ),
      child: child,
    );
  }
}
